package com.itheima.mm.controller;

import com.itheima.mm.dto.QuestionDTO;
import com.itheima.mm.dto.QuestionGetByIdDTO;
import com.itheima.mm.entity.PageResult;
import com.itheima.mm.entity.QueryPageBean;
import com.itheima.mm.entity.QuestionPageQueryParams;
import com.itheima.mm.entity.Result;
import com.itheima.mm.service.QuestionService;
import com.itheima.mm.vo.QuestionMMVO;
import com.itheima.mm.vo.QuestionVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.management.Query;

/**
 * @Description QuestionController
 * @Author xiao
 * @Date 2024-06-25
 */

@Slf4j
@RestController
@RequestMapping("/question")
public class QuestionController {
    @Autowired
    private QuestionService questionService;


    //试题预览接口
    @PostMapping("/getById.do")
    public Result<QuestionVO> getById(@RequestBody QuestionGetByIdDTO questionGetByIdDTO){

        QuestionVO questionVO = questionService.getById(questionGetByIdDTO);
        return Result.success(questionVO);
    }





        //展示和查找试题
    @PostMapping("/findListByPage.do")
    public Result<PageResult<QuestionMMVO>> findListByPage(
            @RequestBody QueryPageBean<QuestionPageQueryParams> queryPageBean){
        log.info("处理试题分页查询请求，请求参数：{}",queryPageBean);


        PageResult<QuestionMMVO> pageResult = questionService.findListByPage(queryPageBean);


        return Result.success(pageResult);

    };



    //试题删除
    @GetMapping("/delete.do")
    public Result delete(Integer questionId){
        log.info("处理删除学科请求，请求学科参数{}",questionId);

        questionService.deleteById(questionId);

        return Result.success(null,"删除成功");



    }




    //添加或者更新试题
    @PostMapping("/addOrUpdate.do")
    public Result addOrUpdate(@RequestBody QuestionDTO questionDTO){
        log.info("开始执行新增更新题库接口：{}",questionDTO);

        questionService.addOrUpdate(questionDTO);

        return Result.success(null,"添加成功");

    }


        //分页查询精选题列表数据
    @PostMapping("/findClassicListByPage.do")
    public Result<PageResult<QuestionMMVO>> findClassicListByPage(@RequestBody QueryPageBean<QuestionPageQueryParams> queryPageBean){

        log.info("开始执行基础题库列表分页查询：{}",queryPageBean);
        //调用业务
        PageResult<QuestionMMVO> pageResult = questionService.findClassicListByPage(queryPageBean);
        //返回数据
        return Result.success(pageResult,"查询成功");
    }


        //加入精选试题
    @GetMapping("/updateClassic.do")
    public Result updateClassic(Integer questionId){

        questionService.updateClassic(questionId);

        return Result.success(null,"加入成功");
    }

















}
